package org.javacourse.service;


import org.javacourse.entity.Customer;

import javax.persistence.Query;
import java.util.List;

public class CustomerService extends AbstractService {

    public Customer getCustomerById(long id){
        //TODO: initializezi em din emf in fiecare metoda
        Query q = em.createQuery("SELECT c FROM Customer c WHERE c.id = :id", Customer.class);
//       TODO:  return em.find(id, Customer.class);
        q.setParameter("id", id);
        return (Customer) q.getSingleResult();
    }

    public Customer deleteCustomerById(long id){
        Query q = em.createQuery("DELETE FROM Customer c WHERE c.id = :id", Customer.class);
        q.setParameter("id", id);
        return (Customer) q.getSingleResult();
        //TODO: transactia nu e pusa
    }

    public List<Customer> getAllCostumers(){
        Query q = em.createQuery("SELECT c FROM Customer c" , Customer.class);
        return (List<Customer>) q.getResultList();
    }



}
